package presentation.controller;

import java.util.List;
import logic.facade.CalendarFacade;
import logic.facade.ProjectFacade;
import vo.CalendarVO;
import vo.StudentVO;
import vo.SubjectVO;

/**
 *
 * @author Alexander
 */
public class ControlPanelCreateSchedule {

    public boolean createSchedule(List<SubjectVO> subjects) {
        CalendarVO calendar = new CalendarVO();
        StudentVO active = new ControlPanelMyAccount().findByIp();
        calendar.setId(active.getCalendarId());
        calendar.setSchedule(subjects);
        calendar.setStudentId(active.getUsername());
        calendar.setCreatedSchedule(true);
        return new CalendarFacade().update(calendar);
    }

    public CalendarVO findCalendar(int calendarId) {
        return (CalendarVO) new CalendarFacade().find(calendarId);
    }

    public boolean deleteSchedule(int calendarioId) {
        CalendarVO calendar = (CalendarVO) new CalendarFacade().find(calendarioId);
        return new CalendarFacade().deleteSchedule(calendar);
    }

    public void createProjectsFromSubjects(List<SubjectVO> subjects) {
        new ProjectFacade().createProjectsFromSubjects(subjects);
    }

    public boolean updateSchedule(List<SubjectVO> newSubjects) {
        StudentVO active = new ControlPanelMyAccount().findByIp();
        CalendarVO calendar = new ControlPanelCreateSchedule().findCalendar(active.getCalendarId());

        deleteSchedule(calendar.getId());

        return createSchedule(newSubjects);
    }
}
